package org.base.oj.controller;

import org.base.oj.common.*;
import org.base.oj.domain.dto.QuestionDTO;
import org.base.oj.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    /**
     * 保存题目
     * @param questionDTO
     * @return
     * @throws BusinessException
     */
    @PostMapping
    public BaseResponse save(@RequestBody QuestionDTO questionDTO) throws BusinessException {
        questionService.saveQuestionAndOptions(questionDTO);
        return ResultUtils.success(questionDTO);
    }

    /**
     * 分页查询题目信息---不含选项
     * @param page
     * @return
     * @throws BusinessException
     */
    @PostMapping("page")
    public BaseResponse page(@RequestBody ParamsPage page) {
        return ResultUtils.success(questionService.getQuestionPage(page));
    }
}
